package com.bingfor.easycablelink.my;

import android.databinding.DataBindingUtil;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.widget.PopupWindowCompat;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.bingfor.easycablelink.R;
import com.bingfor.easycablelink.base.BaseActivity;
import com.bingfor.easycablelink.databinding.AddressListItemBinding;
import com.bingfor.easycablelink.databinding.OrderListItemBinding;
import com.bingfor.easycablelink.utils.ActivityUtil;

/**
 * Created by LY on 2017/2/27.
 */

public class OrderListAdapter extends RecyclerView.Adapter<OrderListAdapter.MessageViewHolder> {


    BaseActivity mContext;


    public OrderListAdapter(  BaseActivity mContext) {
        this.mContext = mContext;

    }
    @Override
    public OrderListAdapter.MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new OrderListAdapter.MessageViewHolder(
                OrderListItemBinding
                        .inflate(LayoutInflater.from(parent.getContext()), parent, false)
                        .getRoot()
        );
    }

    @Override
    public void onBindViewHolder(OrderListAdapter.MessageViewHolder holder, int position) {
        final OrderListItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
        binding.llMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FrameLayout moreOptionView = (FrameLayout) LayoutInflater.from(ActivityUtil.getAppManager().currentActivity()).inflate(R.layout.dialog_exit, null);
                PopupWindow moreOption = new PopupWindow(ActivityUtil.getAppManager().currentActivity());
                moreOption.setContentView(moreOptionView);
                moreOption.setOutsideTouchable(true);
                moreOption.setBackgroundDrawable(new ColorDrawable(0x00000000));
                PopupWindowCompat.showAsDropDown(
                        moreOption,
                        binding.llMore,
                        0,
                        0,
                        Gravity.LEFT
                );
            }
        });



    }

    @Override
    public int getItemCount() {
        return 10;
    }

    protected static class MessageViewHolder extends RecyclerView.ViewHolder {

        public MessageViewHolder(View itemView) {
            super(itemView);

        }
    }
}
